//
//  HJDSuggestViewController.m
//  JYHospital
//
//  Created by 胡金东 on 16/6/15.
//  Copyright © 2016年 胡金东. All rights reserved.
//

#import "HJDSuggestViewController.h"
#import "HJDTextViewLbl.h"

@interface HJDSuggestViewController ()<UITextViewDelegate,UIScrollViewDelegate>

@property (nonatomic,weak) HJDTextViewLbl *textViewLbl;

@property (nonatomic,strong)UIScrollView *scroll;

@end

@implementation HJDSuggestViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor getColorWithHexNumber:@"F1F1EE"];
    self.title = @"建议反馈";
    [self.navigationController.navigationBar setTitleTextAttributes:
     @{NSFontAttributeName:[UIFont systemFontOfSize:19],
       NSForegroundColorAttributeName:[UIColor getColorWithHexNumber:@"848484"]}];
    
    //添加手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTapped:)];
    tap.cancelsTouchesInView = NO;
    [self.view addGestureRecognizer:tap];
    
    [self setUpText];
}

//隐藏键盘
-(void)viewTapped:(UITapGestureRecognizer*)tap
{
    
    [self.view endEditing:YES];
    
}


-(void)setUpText{
    
    self.scroll = [[UIScrollView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.scroll.delegate = self;
    
    self.automaticallyAdjustsScrollViewInsets = YES;
    self.scroll.showsVerticalScrollIndicator = YES;//垂直移动
    self.scroll.showsHorizontalScrollIndicator = NO;//水平移动
    //上下滑动
    self.scroll.contentSize = CGSizeMake(HJDWidth,HJDHeight + 70 ) ;
    
    
    [self.view addSubview: self.scroll];
    

  
    UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(HJDHorizontalMargin , HJDVerticalMargin , 200, 30)];
    lbl.text = @"在下列框中键入您的建议";
    lbl.font = [UIFont systemFontOfSize:15];
    lbl.textColor = [UIColor getColorWithHexNumber:@"848484"];
    [self.scroll addSubview:lbl];
    
    CGFloat resultX = 10 ;
    CGFloat resultY = CGRectGetMaxY(lbl.frame) + 10 ;
    CGFloat resultW = HJDWidth - HJDHorizontalMargin ;
    CGFloat resultH = 250;
    HJDTextViewLbl  *resultTextView = [[HJDTextViewLbl alloc]initWithFrame:CGRectMake(resultX, resultY, resultW, resultH)];
    _textViewLbl = resultTextView;
    resultTextView.placeHolder = @"例如：酸辣粉就算了弗利萨法拉利发了发了发蜡水立方萨拉放家里撒放家里撒";
    resultTextView.font = [UIFont systemFontOfSize:13];
    
    resultTextView.backgroundColor = [UIColor whiteColor];
    [resultTextView setRadius:10 borderWith:0 borderColor:nil];
    
    //    垂直拖拽
    resultTextView.alwaysBounceVertical = YES;
    resultTextView.delegate = self;
    [self.scroll addSubview:resultTextView];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textChange) name:UITextViewTextDidChangeNotification object:nil];
    
    UILabel *phoneLbl = [[UILabel alloc]initWithFrame:CGRectMake(HJDHorizontalMargin, CGRectGetMaxY(resultTextView.frame)+HJDVerticalMargin, 300, 30)];
    phoneLbl.text = @"请留下您的手机号，以便于我们联系您";
    phoneLbl.font = [UIFont systemFontOfSize:15];
    phoneLbl.textColor = [UIColor getColorWithHexNumber:@"848484"];
    [self.scroll addSubview:phoneLbl];
    
    UITextField *field = [[UITextField alloc]initWithFrame:CGRectMake(HJDHorizontalMargin/2, CGRectGetMaxY(phoneLbl.frame) + HJDVerticalMargin/2, HJDWidth - HJDHorizontalMargin, 40)];
    field.backgroundColor = [UIColor whiteColor];
    field.keyboardType = UIKeyboardTypeNumberPad;
    field.clearButtonMode = UITextFieldViewModeAlways;
    [field setRadius:10 borderWith:0 borderColor:nil];
    [self.scroll addSubview:field];
    
    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(HJDHorizontalMargin * 2, CGRectGetMaxY(field.frame) + HJDVerticalMargin, HJDWidth - HJDHorizontalMargin * 4, 40)];
    [btn setTitle:@"提交" forState:UIControlStateNormal];
    [btn setBackgroundColor:[UIColor getColorWithHexNumber:@"5CC6AB"]];
    [btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
    [self.scroll addSubview:btn];
}



-(void)textChange
{
    // 判断下textView有木有内容
    if (_textViewLbl.text.length) {// 有内容
        _textViewLbl.hidePlaceHolder = YES;
        
    }else{
        _textViewLbl.hidePlaceHolder = NO;
    }
}

//开始拖拽，键盘就消失
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    //    让textView中的键盘就消失，自定义的工具条就会消失
    [self.scroll endEditing:YES];
}

-(void)btnClick{
//    HJDLog(@"提交");
}


@end
